#pragma once
class GraphicsEngine;
#include "GameMap.h"
#include "OpenGLWrapper.h"
#include "Viewer.h"
#include "Window.h"
#include "Sun.h"
#include "messageHandler.h"
#include <vector>
#include <fstream>
#include "Drawable.h"
#include "LightSource.h"

using namespace std;
class GraphicsEngine : public MessageHandler
{
public:
						GraphicsEngine(void);
						~GraphicsEngine(void);
						GraphicsEngine(HWND hwnd);
	virtual LRESULT		handle(Window&, UINT, HWND, long, long);
	void				setViewer(Viewer *view);
	void				addLightSource(LightSource *s);
	void				addDrawable(Drawable* d);
	void				setProjectionMatrix(float fov, float zNear, float zFar);

private:
	GLuint				buffers[3], 
						*indexData, 
						fboId, 
						shadowMapUniform,
						depthTextureId,
						MatrixID;

	GLenum				vertexShader,
						fragmentShader,
						programObject;
	OpenGLWrapper		*oGW;

	HDC					hDC;

	vector<Drawable*>	drawables;

	vector<LightSource*> lightSources;
	
	Viewer*				v;

	int					width,
						height;
	unsigned long		getFileLength(ifstream& file);
	void				setTextureMatrix(void);
	void				endTranslate();
	int					loadshader(char* filename, GLubyte*& ShaderSource, unsigned long* &len);
	void				unloadshader(GLubyte** ShaderSource);
	void				startTranslate(float x,float y,float z);
	void				setupShaderProgram();
	void				setupDepthBuffer();

};

